<template>
  <div>
    <div class="login-hd">
      <div class="left-bg"></div>
      <div class="right-bg"></div>
      <div class="hd-inner">
        <span class="logo"></span>
        <span class="split"></span>
        <span class="sys-name">EIP权限工作流</span>
      </div>
    </div>
    <div class="login-bd">
      <div class="bd-inner">
        <div class="inner-wrap">
          <div class="lg-zone">
            <div class="lg-box">
              <div class="lg-label"><h4>用户登录</h4></div>
              <div style="margin: 30px">
                <div class="alert alert-error">
                  <a-alert
                    type="error"
                    :closable="true"
                    v-show="error"
                    :message="error"
                    showIcon
                    style="margin-bottom: 24px"
                  />
                </div>
                <a-form @submit="onSubmit" :form="form">
                  <a-form-item>
                    <a-input
                      autocomplete="autocomplete"
                      size="large"
                      placeholder="请输入账号"
                      v-decorator="[
                        'code',
                        {
                          rules: [
                            {
                              required: true,
                              message: '请输入账户名',
                              whitespace: true,
                            },
                          ],
                        },
                      ]"
                    >
                      <a-icon slot="prefix" type="user" />
                    </a-input>
                  </a-form-item>
                  <a-form-item>
                    <a-input
                      size="large"
                      placeholder="请输入密码"
                      autocomplete="autocomplete"
                      type="password"
                      v-decorator="[
                        'password',
                        {
                          rules: [
                            {
                              required: true,
                              message: '请输入密码',
                              whitespace: true,
                            },
                          ],
                        },
                      ]"
                    >
                      <a-icon slot="prefix" type="lock" />
                    </a-input>
                  </a-form-item>

                  <div>
                    <a-checkbox :checked="true">自动登录</a-checkbox>
                    <a style="float: right">忘记密码</a>
                  </div>
                  <div class="enter">
                    <a-form-item>
                      <a-button
                        :loading="logging"
                        style="width: 100%; margin-top: 24px"
                        size="large"
                        htmlType="submit"
                        type="primary"
                        >登录</a-button
                      >
                    </a-form-item>
                    <div>
                      其他登录方式
                      <a-space>
                        <a-icon class="icon" type="alipay-circle"/>
                        <a-icon class="icon" type="taobao-circle"/>
                        <a-icon class="icon" type="weibo-circle"
                      /></a-space>

                      <router-link
                        style="float: right"
                        to="/dashboard/workplace"
                        >注册账户</router-link
                      >
                    </div>
                  </div>
                </a-form>
              </div>
            </div>
          </div>
          <div class="lg-poster"></div>
        </div>
      </div>
    </div>
    <div class="login-ft">
      <div class="ft-inner">
        <div class="about-us">
          <a href="javascript:;">关于我们</a>
          <a href="javascript:;">法律声明</a>
          <a href="javascript:;">服务条款</a>
          <a
            href="http://wpa.qq.com/msgrd?v=3&uin=1039318332&site=qq&menu=yes"
            target="_blank"
            >联系方式</a
          >
        </div>
        <div class="address">
          QQ
          <a
            href="http://wpa.qq.com/msgrd?v=3&uin=1039318332&site=qq&menu=yes"
            target="_blank"
            ><a-icon type="qq" /> 1039318332</a
          >
          &nbsp;Copyright&nbsp;©&nbsp;2015&nbsp;-&nbsp;2021&nbsp;版权所有
        </div>
        <div class="other-info">
          建议使用IE8及以上版本浏览器&nbsp;蜀ICP备&nbsp;18012364号-1&nbsp;E-mail：<a
            href="mailTo:1039318332@qq.com"
            >1039318332@qq.com</a
          >
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { login, menu } from "@/services/account/login";
import { setAuthorization } from "@/utils/request";
import { mapMutations } from "vuex";
import { loadRoutes } from "@/utils/routerUtil";
export default {
  name: "Login",
  components: {},
  data() {
    return {
      logging: false,
      error: "",
      form: this.$form.createForm(this),
    };
  },
  mounted() {
    this.getCity();
  },
  computed: {
    systemName() {
      return this.$store.state.setting.systemName;
    },
  },
  methods: {
    ...mapMutations("account", ["setUser"]),
    //获取登录地址
    getCity() {},

    onSubmit(e) {
      e.preventDefault();
      this.form.validateFields((err) => {
        if (!err) {
          this.logging = true;
          const code = this.form.getFieldValue("code");
          const password = this.form.getFieldValue("password");
          const returnCitySN = JSON.parse(
            sessionStorage.getItem("returnCitySN")
          );
          const remoteIp = returnCitySN.cip;
          const remoteIpAddress = returnCitySN.cname;
          const navigator = returnCitySN.navigator;
          login(code, password, remoteIp, remoteIpAddress, navigator).then(
            this.afterLogin
          );
        }
      });
    },
    afterLogin(result) {
      const loginRes = result;
      if (loginRes.code === this.$resultCode.success) {
        this.setUser(result.data);
        //获取菜单
        var routesConfig = [
          {
            router: "root",
            children: [
              {
                router: "analysis",
                path: "/dashboard/analysis",
                meta: {
                  icon: "windows",
                  page: {
                    closable: false,
                  },
                },
              },
            ],
          },
        ];

        setAuthorization({
          token: loginRes.data.token,
          expire: new Date(loginRes.data.expire),
        });

        //注册路由
        menu().then((result) => {
          result.forEach((element) => {
            routesConfig[0].children.push(element);
          });
          loadRoutes(routesConfig);
          this.$router.push("/dashboard/analysis");
          this.$message.success(loginRes.msg, 3);
        });
      } else {
        this.error = loginRes.msg;
      }
      this.logging = false;
    },
  },
};
</script>

<style lang="less" scoped>
html,
body {
  height: 100%;
}
body {
  background-color: #fff;
}
body .login-hd {
  background: #fff;
}
body .login-hd .logo {
  background: url(./images/login_logo_w.png) no-repeat;
}
body .login-bd {
  background-color: @primary-color;
}
body .login-bd .lg-zone {
  background: url(./images/login_bg_tubiao.png) center 46px no-repeat;
}
body.white .login-bd .lg-zone {
  background: url(./images/login_bg_tubiao.png) center 46px no-repeat;
}
body.white .login-bd .lg-zone .lg-box .lg-label h4 {
  border-left: none;
}
.login-hd {
  position: relative;
  height: 94px;
  background: #05a7d8;
  line-height: 94px;
  min-width: 1200px;
}
.login-hd .left-bg {
  position: absolute;
  width: 348px;
  height: 92px;
  left: 0;
  top: 0;
}
.login-hd .right-bg {
  position: absolute;
  width: 267px;
  height: 92px;
  right: 0;
  top: 0;
}
.login-hd .hd-inner {
  width: 1200px;
  height: 94px;
  line-height: 94px;
  margin: 0 auto;
}
.login-hd .hd-inner .logo {
  position: relative;
  display: inline-block;
  width: 245px;
  height: 73px;
  margin-left: 15px;
  margin-top: 10px;
  margin-right: 10px;
}
.login-hd .hd-inner .split {
  position: relative;
  display: inline-block;
  height: 32px;
  width: 1px;
  top: -17px;
  margin-right: 10px;
  background-color: #4fbee0;
}
body .login-hd .hd-inner .split {
  background-color: #ccc;
}
.login-hd .hd-inner .sys-name {
  display: inline-block;
  position: relative;
  color: #000;
  font-size: 22px;
  top: -31px;
}
.login-bd {
  position: relative;
  border: 1px solid #e5e5e5;
  background-color: #fff;
  min-width: 1200px;
}
.login-bd .bd-inner {
  width: 1200px;
  margin: 0 auto;
}
.login-bd .bd-inner .inner-wrap {
  position: relative;
  padding-right: 504px;
}
.login-bd .bd-inner .inner-wrap .lg-zone {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 504px;
}

.login-bd .bd-inner .inner-wrap .lg-zone .lg-box {
  position: absolute;
  right: 30px;
  top: 46px;
  background: #fff;
  box-shadow: 2px 2px 3px #ddd, -2px 0 3px #ddd;
  width: 364px;
  padding-bottom: 20px;
}
body .login-bd .bd-inner .inner-wrap .lg-zone .lg-box {
  position: absolute;
  right: 30px;
  top: 46px;
  background: #fff;
  box-shadow: 0px 0px 0px #ddd, -0px 0 0px #ddd;
  width: 364px;
  padding-bottom: 20px;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .line {
  position: absolute;
  left: 0;
  top: 0;
  height: 6px;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .line.line-y {
  width: 127px;
  background: #f45438;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .line.line-g {
  left: 127px;
  right: 0;
  background: #05a7d8;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .lg-label {
  color: #000;
  font-size: 22px;
  height: 44px;
  line-height: 44px;
  margin-top: 23px;
  text-indent: 30px;
  margin-bottom: 20px;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .lg-label h4 {
  border-left: 4px solid @primary-color;
}
body .login-bd .bd-inner .inner-wrap .lg-zone .lg-box .lg-label h4 {
  border-left: 4px solid @primary-color;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .input-item {
  margin-bottom: 22px;
  width: 296px;
  line-height: 40px;
  height: 40px;
  border-top: 1px solid #adadad;
  border-left: 1px solid #adadad;
  border-right: 1px solid #cfcfcf;
  border-bottom: 1px solid #cfcfcf;
  margin-left: 34px;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .input-item i {
  float: left;
  display: inline-block;
  width: 40px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  color: #5d5c68;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .input-item input {
  border: 0;
  height: 40px;
  padding: 0;
  width: 236px;
  float: left;
  outline: none;
  text-decoration: none;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .input-item input:focus {
  outline: none;
  text-decoration: none;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .lg-check {
  margin-bottom: 10px;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .lg-check .input-item {
  float: left;
  width: 172px;
  margin-right: 10px;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .lg-check .input-item input {
  width: 132px;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .lg-check .check-code {
  float: left;
  display: inline-block;
  height: 42px;
  line-height: 42px;
  background-color: #ff9d02;
  color: #fff;
  width: 114px;
  text-align: center;
  font-size: 14px;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .tips {
  height: 20px;
  line-height: 20px;
  margin-bottom: 30px;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .tips input[type="checkbox"] {
  position: relative;
  margin-left: 34px;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .tips label {
  font-size: 14px;
  color: #a3a3a3;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .tips a {
  float: right;
  font-size: 12px;
  text-decoration: none;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .tips a:hover {
  text-decoration: underline;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .tips a.register {
  color: #05a7d8;
  margin-left: 12px;
  margin-right: 34px;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .tips a.forget-pwd {
  color: #000;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .enter a {
  display: inline-block;
  text-decoration: none;
  height: 48px;
  line-height: 48px;
  text-align: center;
  color: #fff;
  font-size: 16px;
  width: 142px;
  font-weight: bold;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .enter a.purchaser {
  margin-left: 34px;
  background-color: #f45438;
  margin-right: 9px;
}
.login-bd .bd-inner .inner-wrap .lg-zone .lg-box .enter a.supplier {
  background-color: #05a7d8;
}
.login-bd .bd-inner .inner-wrap .lg-poster {
  height: 541px;
  background: url(./images/loginbg.png) right center no-repeat;
}
.login-ft {
  padding-top: 20px;
  min-width: 1200px;
}
.login-ft .ft-inner {
  margin: 0 auto;
}
.login-ft .ft-inner .about-us {
  height: 20px;
  line-height: 20px;
  width: 295px;
  margin: 0 auto;
  margin-bottom: 10px;
}
.login-ft .ft-inner .about-us a {
  color: #666;
  text-decoration: none;
  font-size: 14px;
  float: left;
  margin-left: 15px;
}
.login-ft .ft-inner .about-us a:hover {
  text-decoration: underline;
}
.login-ft .ft-inner .address {
  text-align: center;
  color: #999;
  font-size: 12px;
  margin-bottom: 10px;
}
.login-ft .ft-inner .other-info {
  text-align: center;
  color: #999;
  font-size: 12px;
  margin-bottom: 50px;
}
</style>
